package com.whiteape.book.ui.adapter;

import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.model.bo.SearchResultBo;
import com.whiteape.book.model.dto.SiteSourceBean;
import com.whiteape.book.model.type.RVLayoutType;

import java.util.ArrayList;
import java.util.List;

public class ChangeSourceAdapter extends BaseQuickAdapter<SearchResultBo, BaseViewHolder> {


    private SiteSourceBean currentSiteSource;
    private String currentAuthor;

    public SiteSourceBean getCurrentSiteSource() {
        return currentSiteSource;
    }

    public void setCurrentSiteSource(SiteSourceBean currentSiteSource) {
        this.currentSiteSource = currentSiteSource;
    }

    public void setCurrentAuthor(String author) {
        this.currentAuthor = author;
    }

    public ChangeSourceAdapter(int layoutResId, @Nullable List<SearchResultBo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchResultBo item) {

        helper.setVisible(R.id.ll_current_use, item.getSiteSourceBean().getSiteHostUrl().equals(currentSiteSource.getSiteHostUrl())
                && item.getAuthor().equals(currentAuthor));
        helper.setText(R.id.tv_web_source_title, item.getSiteSourceBean().getSiteName());
        helper.setText(R.id.tv_author, "作者：" + item.getAuthor());
        helper.setText(R.id.tv_last_chapter, item.getLastChapter());
        Glide.with(mContext)
                .load(item.getSiteSourceBean().getSiteIconUrl())
                .placeholder(R.mipmap.no_cover_landscape)
                .fitCenter()
                .into((ImageView) helper.getView(R.id.iv_site_cover));

    }

}
